﻿// -
// <copyright file="TextArea.xaml.cs" company="Microsoft Corporation">
//    Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// -
using System.Windows.Controls;
using OcrSampleApp.Data;
using OcrSampleApp.ViewModels;
using System.Globalization;
using System.Windows;
using System;
using Microsoft.Phone.Tasks;

namespace OcrSampleApp.Controls
{
    /// <summary>
    /// TextArea class contains the code behind for the TextArea user control.
    /// The TextArea user control shows to the user the text resulted from the OCR conversion.
    /// </summary>
    public partial class TextArea : UserControl
    {


        /// <summary>
        /// Initializes a new instance of the TextArea class.
        /// </summary>
        public TextArea()
        {
            InitializeComponent();
            this.DataContext = new MyViewModel(OcrData.Instance, OcrConversionStateManager.Instance);

          
        }

       

        public void btnCall_Click(object sender, RoutedEventArgs e)
        {
           // phoneNumberChooserTask.Show();

            MyWord word = (MyWord)(((Button)e.OriginalSource).DataContext);

            PhoneCallTask phoneTask = new PhoneCallTask();
            phoneTask.PhoneNumber = word.MyText;
            phoneTask.Show();

        }
        private void btnSaveNumber_Click(object sender, RoutedEventArgs e)
        {
            MyWord word = (MyWord)(((Button)e.OriginalSource).DataContext);
            SavePhoneNumberTask saveNumberTask = new SavePhoneNumberTask();
            saveNumberTask.PhoneNumber = word.MyText;
            saveNumberTask.Show();
        }

        public void btnEmail_Click(object sender, RoutedEventArgs e)
        {
            MyWord word = (MyWord)(((Button)e.OriginalSource).DataContext);

            EmailComposeTask emailComposeTask = new EmailComposeTask();
            emailComposeTask.Subject = "Hello";
            emailComposeTask.Body = "Your e-mail address has just been recognized!";
            emailComposeTask.To = word.MyText;            
            emailComposeTask.Show();

        }

        private void btnSaveEmailAddress_Click(object sender, RoutedEventArgs e)
        {
            MyWord word = (MyWord)(((Button)e.OriginalSource).DataContext);

            SaveEmailAddressTask saveTask = new SaveEmailAddressTask();
            saveTask.Email = word.MyText;
            saveTask.Show();
        }


        private void btnUrl_Click(object sender, RoutedEventArgs e)
        {
            MyWord word = (MyWord)(((Button)e.OriginalSource).DataContext);

            WebBrowserTask webBrowsertask = new WebBrowserTask();
            webBrowsertask.Uri = new Uri(word.MyAbsoluteLink, UriKind.Absolute);           
            webBrowsertask.Show();

        }


    }
}
